import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


class Animal{


}
class Dog extends Animal{

    public int age=19;
    public String name="dwd";

    public Dog(int age, String name) {
        this.age = age;
        this.name = name;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "age=" + age +
                ", name='" + name + '\'' +
                '}';
    }
}

class Cat extends Animal{



}
class MyArray<T>{

    public Object[] array=new Object[10];

    public void setArray(int pos, T val){

        array[pos]=val;
    }
    public T get(int pos){

        return (T)array[pos];
    }



}
class Alg<T extends Comparable<T>>{

    public static<T > void func(ArrayList<T> array){
        //泛型方法
        for (T x:array) {
            System.out.println(x);
        }

    }

    public static void func1(ArrayList<?> arrayList){

        //？是通配符表示的是一个范围扩充所以要定义一个Object类型来接受
        for (Object O:arrayList
             ) {
            System.out.println(O);
        }
    }
        public T num(T[] t){
        T max=t[0];
        for(int i=0;i<t.length;i++){
            if(t[i].compareTo(max)>0){

                max=t[i];
            }

        }
        return max;


    }

    public static <T extends Animal> void func3(List<T> list){


        for (T animal: list
             ) {
            System.out.println(list);
        }
    }

}

public class Test {

    public static void main(String[] args) {
        ArrayList<Dog> arrayList=new ArrayList<>();
        Alg.func3(arrayList);
    }

    public static void main3(String[] args) {

        /*Alg<Integer> alg1=new Alg<>();
        Integer[] integer={1,2,3};*/
        ArrayList<Integer> arrayList=new ArrayList<>();
        arrayList.add(1);
        arrayList.add(2);
        Alg.<Integer>func(arrayList);//根据传入的类型自动识别类型
        System.out.println("===========");
        Alg.func1(arrayList);


    }
    public static void main2(String[] args) {
        Alg<Integer> integerAlg=new Alg<>();

        Integer[] integers=new Integer[]{1,6,7,5,6,7,77};

        System.out.println(integerAlg.num(integers));
    }
    public static void main1(String[] args) {
       MyArray<Integer> myArray=new MyArray<>();

       Integer integers=myArray.<Integer>get(0);
        /*        myArray.setArray(0,11);
        myArray.setArray(1,11);
        myArray.setArray(2,11);
        myArray.setArray(3,11);
        System.out.println(myArray.array[0]);
        System.out.println(myArray.array[1]);
        System.out.println(myArray.array[2]);
        System.out.println(myArray.array[3]);
        System.out.println(myArray.array[4]);

        System.out.println("sd");*/
    }
}
